package com.fan.txl.ui;

import android.graphics.Point;
import android.os.Bundle;
import android.view.TextureView;

import com.fan.txl.R;
import com.fan.txl.ui.base.BaseActivity;
import com.ragnarok.rxcamera.RxCamera;
import com.ragnarok.rxcamera.config.RxCameraConfig;

import io.reactivex.ObservableSource;
import io.reactivex.functions.Function;

public class PhotosUI extends BaseActivity {
    TextureView textureView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photos_ui);
        textureView=(TextureView)findViewById(R.id.textureView);

        RxCameraConfig config = new RxCameraConfig.Builder()
                .useBackCamera()
                .setAutoFocus(true)
                .setPreferPreviewFrameRate(15, 30)
                .setPreferPreviewSize(new Point(640, 480), false)
                .setHandleSurfaceEvent(true)
                .build();


        RxCamera.open(this, config).flatMap(new Function<RxCamera, ObservableSource<RxCamera>>() {
            @Override
            public ObservableSource<RxCamera> apply(RxCamera rxCamera) throws Exception {
                return rxCamera.bindTexture(textureView);
            }
        }).flatMap(new Function<RxCamera, ObservableSource<RxCamera>>() {
            @Override
            public ObservableSource<RxCamera> apply(RxCamera rxCamera) throws Exception {
                return rxCamera.startPreview();
            }
        });
    }
}
